﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KYO.DAL;
using ObjectPersistence;
public partial class Admin_Controls_Mod_Slide_SlideEdit : Controller<ProjectSlide>
{
    ProjectSlideAssembler service = new ProjectSlideAssembler();
    List<Message> list = new List<Message>();
    ViewControlBase<ProjectSlide> ViewControlBase1;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            MessageBox1.Visible = false;
            
            int id = GetID("id");
            Model = service.ReadSingleByKey(id);
            if (Model == null) View("Warring");
            ViewControlBase1.UpdateView(Model);
        }
    }

    protected override void OnInit(EventArgs e)
    {
        InitializeComponent();
        base.OnInit(e);
    }

    private void InitializeComponent()
    {
        SaveTool1.SaveClick += new EventHandler(SaveTool1_SaveClick);
        SaveTool1.CancelClick += new EventHandler(SaveTool1_CancelClick);
        SaveTool1.ApplyClick += new EventHandler(SaveTool1_ApplyClick);
        ViewControlBase1 = (ViewControlBase<ProjectSlide>)FindControl("Slide1");
    }

    void SaveTool1_ApplyClick(object sender, EventArgs e)
    {

        try
        {
            Model = ViewControlBase1.UpdateModel(Model);
            service.MakePersistent(Model, true);
            list.Add(new Message("Insert Is successful!"));
            ViewMessage(list, MessageType.Success);

        }
        catch (Exception ex)
        {
            list.Add(new Message("Update Is Fail!"));
            list.Add(new Message(ex.Message));
            ViewMessage(list, MessageType.Error);
        }
    }

    void SaveTool1_CancelClick(object sender, EventArgs e)
    {
        View("Slide", "List");
    }

    void SaveTool1_SaveClick(object sender, EventArgs e)
    {


        try
        {
            ViewControlBase1.UpdateModel(Model);
            service.MakePersistent(Model, true);
            View("Slide", "List");
        }
        catch (Exception ex)
        {


            list.Add(new Message("Update Is fail!"));
            list.Add(new Message(ex.Message));
            ViewMessage(list, MessageType.Error);
        }

    }




}
